import React, { Component, useState, useEffect } from "react";

export default function UseEffect() {
  const [num, setnum] = useState(10);

  useEffect(() => {
    console.log("页面加载");
    console.log("实时的num为"+num);
  },[num]);

  
  useEffect(() => {
    return () => {
      console.log("页面销毁");
    };
  },[]);
  let add = () => {
    setnum(num + 1);
  };

  return (
    <div>
      UseEffect 模拟生命周期
      <div>数据 {num}</div>
      <button onClick={add}>修改</button>
    </div>
  );
}
